import { createRouter,createWebHashHistory } from 'vue-router'
import 'nprogress/nprogress.css'
import NProgress from 'nprogress'


//定义路由
const routesx = [
    { path: '/', 
      name:'Main',
      component: import('../components/rmain.vue') ,
      children:[ //子路由
       { path: '/', 
         name:'Wellcome',
         component: import('../components/wellcome.vue')  //欢迎界面
       },
        { path: '/room', 
          name:'Room',
          component: import('../components/room.vue')
        },
        { path: '/sysuser', 
          name:'Sysuser',
          component: import('../components/sysuser.vue')
        },
        { path: '/reservation', 
          name:'Reservation',
          component: import('../components/reservation.vue')
        },
        { path: '/discountactivities', 
          name:'Discountactivities',
          component: import('../components/discountactivities.vue')
        }
      ]
    },
    { path: '/login', 
      name:'Login',
      component: import('../components/login.vue') 
    },
    { path: '/test', 
    name:'Test',
    component: import('../components/test.vue') 
    },
    { path: '/test2', 
    name:'Test2',
    component: import('../components/test2.vue') 
    },
    { path: '/testroom', 
    name:'Test2',
    component: import('../components/testroom.vue') 
    },
    { path: '/testupload', 
    name:'Test4',
    component: import('../components/test4.vue') 
    },
    { path: '/test5', 
    name:'Test5',
    component:() =>  import('../components/test5.vue') 
    },
    { path: '/test6', 
    name:'Test6',
      component: () => import('../components/test6.vue') 
    },
    { path: '/test7', 
    name:'Test7',
      component: () => import('../components/test7.vue') 
    },
    { path: '/test8', 
    name:'Test8',
      component: () => import('../components/test8.vue') 
    },
    { path: '/test9', 
    name:'Test9',
      component: () => import('../components/test9.vue') 
    }
]


//创建路由对象
const router = createRouter({
    history: createWebHashHistory(),
    routes:routesx // `routes: routes` 的缩写
})

//导航守卫
router.beforeEach(function(to,from){
  console.log("导航守卫 --beforeEach ");
  NProgress.start(); //开启进度条
  return true;  //false 取消当前的导航
})

router.afterEach(function(to,from){
 console.log("导航守卫 --afterEach ");
 NProgress.done();  //完成进度条
})

export default router